from selenium import webdriver

# 初始化Chrome浏览器
driver = webdriver.Chrome()

# 访问百度首页
driver.get("https://www.baidu.com")

try:
    # 新增一个Cookie
    driver.add_cookie({"name": "test_cookie", "value": "test_value"})

    # 删除指定Cookie
    driver.delete_cookie("test_cookie")

    # 获取所有Cookie信息并输出
    cookies = driver.get_cookies()
    print("删除Cookie后的信息：")
    for cookie in cookies:
        print(f"Name: {cookie['name']}, Value: {cookie['value']}")

except Exception as e:
    print(f"操作失败：{e}")

finally:
    # 关闭浏览器
    driver.quit()